<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0px;
      }
      ul,
      li {
        list-style: none;
      }
      img {
        width: 100%;
        height: 100%;
        display: block;
      }
      .banner {
        width: 300px;
        height: 300px;
        position: relative;
        margin: 100px auto;
      }

      .banner > ul {
        width: 100%;
        height: 100%;
        position: relative;
        top: 0;
        left: 0;
      }
      .banner > ul > li {
        width: 100%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        opacity: 0;
        transition: opacity 0.5s linear;
      }
      .banner > ul > li.active {
        opacity: 1;
      }

      .banner > div {
        width: 40px;
        height: 60px;
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        background-color: rgba(0, 0, 0, 0.5);
        display: flex;
        justify-content: center;
        font-size: 40px;
        color: #fff;
      }
      .banner > div.left {
        left: 0;
      }
      .banner > div.right {
        right: 0;
      }
      .banner > ol > li {
        list-style: none;
        margin: 0;
        padding: 0;
      }
      .banner > ol {
        width: 200px;
        height: 30px;
        display: flex;
        justify-content: space-around;
        align-items: center;
        background: violet;
        margin: 0px;
        padding: 0px;
        position: absolute;
        left: 20px;
        bottom: 30px;
      }
      .banner > ol > li {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background: cornsilk;
      }
      .banner > ol > .active {
        background: orange;
      }
    </style>
  </head>
  <body>
    <div class="banner">
      <ul class="imgbox">
        <li class="active"><img src="images/0.jpg" alt="" /></li>
        <li><img src="images/1.jpg" alt="" /></li>
        <li><img src="images/2.jpg" alt="" /></li>
        <li><img src="images/3.jpg" alt="" /></li>
        <li><img src="images/4.jpg" alt="" /></li>
        <li><img src="images/5.jpg" alt="" /></li>
        <li><img src="images/6.jpg" alt="" /></li>
        <li><img src="images/7.jpg" alt="" /></li>
        <li><img src="images/8.jpg" alt="" /></li>
      </ul>
      <ol>
        <li data-i="0" data-name="point" class="active"></li>
        <li data-i="1" data-name="point"></li>
        <li data-i="2" data-name="point"></li>
        <li data-i="3" data-name="point"></li>
        <li data-i="4" data-name="point"></li>
        <li data-i="5" data-name="point"></li>
        <li data-i="6" data-name="point"></li>
        <li data-i="7" data-name="point"></li>
        <li data-i="8" data-name="point"></li>
      </ol>

      <div class="left">&lt;</div>
      <div class="right">&gt;</div>
    </div>
    <script>
      var banner = document.querySelector(".banner");
      var imgs = document.querySelectorAll("ul>li");
      var points = document.querySelectorAll("ol>li");
      var index = 0;
      function changeone(type) {
        imgs[index].className = "";
        points[index].className = "";

        if (type === true) {
          index++;
        } else if (type === false) {
          index--;
        } else {
          index = type;
        }
        if (index >= imgs.length) {
          index = 0;
        }
        if (index < 0) {
          index = imgs.length - 1;
        }
        imgs[index].className = "active";
        points[index].className = "active";
      }
      banner.onclick = function (e) {
        if (e.target.className === "left") {
          console.log("zuo");
          changeone(false);
        }
        if (e.target.className === "right") {
          console.log("you");
          changeone(true);
        }
        if (e.target.dataset.name === "point") {
          console.log("jiaodian ");
          var i = e.target.dataset.i - 0;
          changeone(i);
        }
      };
      var timer = setInterval(function () {
        changeone(true);
      }, 1000);
      banner.onmouseenter = function () {
        clearInterval(timer);
      };
    </script>
  </body>
</html>
